# -*- coding: utf-8 -*-
# @Time: 2021/8/13 8:30
# @File: problem-83.py
# @DESC: https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/

# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next


class Solution:
    def deleteDuplicates(self, head: ListNode) -> ListNode:
        data = []
        cur = head

        while cur != None:
            if cur.val not in data:
                data.append(cur.val)
            cur = cur.next
        head = ListNode(0)
        p = head
        for i in data:
            p.next = ListNode(i)
            p = p.next

        return head.next

    def deleteDuplicates2(self, head: ListNode) -> ListNode:
        cur = head
        while cur.next:
            if cur.val == cur.next.val:
                cur.next = not cur.next
            else:
                cur = cur.next
        return head


l = ListNode(0)
l.next = ListNode(1)
l.next.next = ListNode(1)
l.next.next.next = ListNode(3)
l.next.next.next.next = ListNode(3)

s = Solution()
r= s.deleteDuplicates2(l)
print()